﻿using daonaite.core.Attribute;
using daonaite.Model.system.role_menu;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace daonaite.DAL.system
{
    [AutoLoad]
    public class D_role_menu
    {
        private readonly ISqlSugarClient client;

        public D_role_menu(ISqlSugarClient client)
        {
            this.client = client;
        }

        /// <summary>
        /// 获取信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<sys_role_menu> get(int id)
        {
            var result = await client.Queryable<sys_role_menu>().FirstAsync(x => x.id == id);
            return result;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<int> add(sys_role_menu data)
        {
            return await client.Insertable(data).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
        }

        /// <summary>
        /// 根据角色查询菜单
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public async Task<sys_role_menu> getbyroleAsync(int roleid)
        {
            var result = await client.Queryable<sys_role_menu>().Where(x => x.roleId == roleid).FirstAsync();
            return result;
        }

        /// <summary>
        /// 更新菜单项
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<int> update_mensidAsync(sys_role_menu data)
        {
            return await client.Updateable<sys_role_menu>().SetColumns(s => s.menuIds == data.menuIds).Where(it => it.roleId == data.roleId).ExecuteCommandAsync();
        }
    }
}
